/**
 * Created by cheny on 2016/7/28.
 */
(function(){
    'use strict';
    app.factory('userOrderService',['$http','$q',function($http,$q){
        $http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded";
        var factory={
            getOrderDetail:getOrderDetail,
            getOrderList:getOrderList
        };
        return factory;

        function getOrderDetail(orderId){

            var deferred=$q.defer();
            var promise=$http.get("/order/getuserorderdetail?orderId="+orderId);
            promise.then(
                function(success){
                    deferred.resolve(success.data);
                },
                function(error){
                    console.log(error);
                    deferred.reject(error);
                });
            return promise;
        }
        function getOrderList(goodsName,startTime,endTime,label,currentPage){
            var deferred=$q.defer();
            var queryCondition={
                goodsName:goodsName,
                orderStartTime:startTime,
                orderEndTime:endTime,
                tag:label,
                currentPage:currentPage
            }
            var promise=$http.post("/order/getuserorderpagelist",$.param(queryCondition));
            promise.then(
                function(success){
                    deferred.resolve(success.data);
                },
                function(error){
                    console.log(error);
                    deferred.reject(error);
                });
            return promise;
        }
    }]);
})();
